//
//  BecomeExpertViewController.m
//  DaJiang
//
//  Created by sally on 16/10/6.
//  Copyright © 2016年 jiniu. All rights reserved.
//

#import "BecomeExpert1Cell.h"
#import "BecomeExpert2Cell.h"
#import "BecomeExpertViewController.h"
#import "CellManager.h"
#import "ExpertInfoEditViewController.h"

@interface BecomeExpertViewController ()

@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet UIView *headerView;
@property (strong, nonatomic) NSMutableArray *tableData;

@end

@implementation BecomeExpertViewController

- (void)viewDidLoad {
  [super viewDidLoad];
  [self initControl];
  [self initData];
}

#pragma mark 初始化控件
- (void)initControl {
  self.title = @"成为专家";
  self.headerView.height = GHeadViewHeight;
  [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
}

#pragma mark 初始化数据
- (void)initData {
  self.tableData = [NSMutableArray array];
  [self.tableData addObject:@[ @"成为专家你可以", @"发现个人价值；塑造个人品牌；分享经验知识；结识更多专家" ]];
  [self.tableData addObject:@[ @"大匠平台资源", @"这里有建筑工程领域众多的学者、专家、企业高管和跨界人士，这里也有成千上万的求知者。这是一个传播知识和智慧的共享平台，畅打开您的心扉，体验传授知识和智慧的快乐！" ]];
  [self.tableData addObject:@[ @"如何成为专家", @"1.申请当专家  2.完善资料  3.发布服务  4.等待审核  5.成为专家" ]];
}

#pragma mark - action
#pragma mark 点击申请
- (IBAction)actionOnApply:(id)sender {
  ExpertInfoEditViewController *vc = [[ExpertInfoEditViewController alloc] init];
  [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - TableView data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  return self.tableData.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  return [[self.tableData objectAtIndex:section] count];
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  return GNormalMargin; //section头部高度
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  return 0.1; //section底部高度
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  if (indexPath.row == 0) {
    return NavHeight;
  } else if (indexPath.section == 0 || indexPath.section == 2) {
    UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
    return cell.frame.size.height;
  } else {
    return 90;
  }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  if (indexPath.section == 0 && indexPath.row == 1) {
    BecomeExpert1Cell *cell = (BecomeExpert1Cell *) [tableView dequeueReusableCellWithIdentifier:@"BecomeExpert1Cell"];
    if (!cell) {
      cell = [[[NSBundle mainBundle] loadNibNamed:@"BecomeExpert1Cell" owner:nil options:nil] lastObject];
    }

    return cell;
  } else if (indexPath.section == 2 && indexPath.row == 1) {
    BecomeExpert2Cell *cell = (BecomeExpert2Cell *) [tableView dequeueReusableCellWithIdentifier:@"BecomeExpert2Cell"];
    if (!cell) {
      cell = [[[NSBundle mainBundle] loadNibNamed:@"BecomeExpert2Cell" owner:nil options:nil] lastObject];
    }

    return cell;
  } else {
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];

    //主标题
    [CellManager configCellText:cell type:TextColorType_Black];
    cell.textLabel.text = [[self.tableData objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
    cell.textLabel.numberOfLines = 0;
    cell.textLabel.font = GFontWithSize(GMiddleFontSize);
    if (indexPath.row == 0) {
      cell.textLabel.textAlignment = NSTextAlignmentCenter;
      cell.textLabel.font = GFontWithSize(GLargeFontSize);
      cell.textLabel.textColor = GOrangeColor;
    }
    return cell;
  }
}

@end
